﻿new Vue({
    el: "#divSupplementSetting",
    data: {
        search: { area: '', time: '', count: 0 },
        form: { 
            name: '',
            gender: 1,
            certificateType: 1,
            idNo: '',
            mobilePhone: '',
            educationType: 1,
            area: '',
            domicile: '',
            schoolName: '',
            specialityName: ''
        },
        certificateTypeList: [
            { id: 1, name: "居民身份证" },
            { id: 2, name: "港澳台身份证" },
            { id: 3, name: "华侨身份证" },
            { id: 4, name: "护照" },
            { id: 5, name: "其他" },
        ],
        genderList: [
            { id: 1, name: "男" },
            { id: 0, name: "女" }
        ],
        educationTypeList: [
            { id: 1, name: "无" },
            { id: 2, name: "小学" },
            { id: 3, name: "初中" },
            { id: 4, name: "高中" },
            { id: 5, name: "中专" },
            { id: 6, name: "大专" },
            { id: 7, name: "本科" },
            { id: 8, name: "其他" },
        ],
        sptSet: {
            totalCount: 0,
            applyCount: 0,
            endTime: '',
            residueCount: 0
        },
        rules: {
            name: [
                { required: true, message: '请输入姓名', trigger: 'blur' }
            ],
            gender: [
                { required: true, message: '请选择性别', trigger: 'change' }
            ],
            certificateType: [
                { required: true, message: '请选择证件类型', trigger: 'change' }
            ],
            idNo: [
                { required: true, message: '请输入证件号码', trigger: 'blur' }
            ],
            mobilePhone: [
                { required: true, message: '请输入手机号码', trigger: 'blur' }
            ],
            educationType: [
                { required: true, message: '请选择现阶段学历', trigger: 'change' }
            ],
            area: [
                { required: true, message: '请输入地区', trigger: 'blur' }
            ],
            domicile: [
                { required: true, message: '请输入户口', trigger: 'blur' }
            ],
            schoolName: [
                { required: true, message: '请输入报考学校', trigger: 'blur' }
            ],
            specialityName: [
                { required: true, message: '请输入报考专业', trigger: 'blur' }
            ]
        },
    }, mounted: function () {
        this.resetForm();
        VmTop.navOn = 1;
        this.getSupplementSetting();
    },
    methods: {
        //保存模板信息
        saveStudent: function () {
            that = this;
            this.$refs['form'].validate(function (valid) {
                if (valid) {
                    if (that.form.totalCount < that.form.applyCount) {
                        VmYz.message("已申请数量应小于总名额", false);
                        return;
                    }
                    that.loading = true;
                    $.post("/student/save", that.form, function (data) {
                        VmYz.message(data.msg, data.suc);
                        if (data.suc) {
                            that.resetForm();
                        }
                        that.loading = false;
                    });
                }
            });
        },
        resetForm: function () {
            this.form = { 
                name: '',
                gender: 1,
                certificateType: 1,
                idNo: '',
                mobilePhone: '',
                educationType: 1,
                area: '',
                domicile: '',
                schoolName: '',
                specialityName: ''
            };
        },
        //列表属性转换
        formatDate: function (value) {
            return value.split(" ")[0];
        },
        getSupplementSetting: function () {
            var that = this;
            $.getJSON("/student/GetSupplementSet", function (res) { 
                that.sptSet = res.data;
                that.sptSet.residueCount = that.sptSet.totalCount - that.sptSet.applyCount;
                if (that.search.count > 0) {
                    VmYz.message("查询完成", true);
                }
                that.search.count += 1;
            })
        }
    }
});